package com.cskaoyan.javase.method._5overload._2exercise;

/**
 * @description: 计算器类
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Calculator {
    public static void main(String[] args) {
        System.out.println(power(2, 10));
    }

    //加
    public static int add(int num1, int num2) {
        return num1 + num2;
    }
    public static double add(double num1, double num2) {
        return num1 + num2;
    }

    //减
    public static int subtract(int num1, int num2) {
        return num1 - num2;
    }

    //乘
    public static int multiply(int num1, int num2) {
        return num1 * num2;
    }

    //除
    public static double divide(double num1, double num2) {
        return num1 / num2;
    }

    //求平方
    public static int square(int num1) {
        return num1 * num1;
    }

    //幂运算
    public static int power(int num1, int n) {
        //使用循环来完成重复的事情
        //int result = 1;
        //for (int i = 0; i < n; i++) {
        //    result *= num1;
        //}
        //return result;

        //Math.pow(double,double)
       return ((int) Math.pow(num1, n));
    }
}
